<?php

class Globalmodel extends CI_Model {

    public function __construct() {
        parent::__construct();
    }
    
    public function login($email="", $password="", $open_login=false) {
        $email = mysql_real_escape_string($email);
        $password =  mysql_real_escape_string($password);
        $query = "SELECT * FROM users WHERE email='$email' AND password='$password'";
        $res = $this->db->query($query);
        if ($res == null) {
            throw new Exception($this->db->_error_message(), 2);
        } else {
            $res = $res->result();
        }

        if (count($res) == 0) {
            if($open_login==true){
                return (object) array('id'=>'-1','email'=>$email);
            }
            return null;
        } else
            return $res[0];
    }

    public function get_user_detail_by_email($email=""){
        $email = mysql_real_escape_string($email);
        $query = "SELECT * FROM users WHERE email='$email'";
        $res = $this->db->query($query);
        if ($res == null) {
            throw new Exception($this->db->_error_message(), 2);
        } else {
            $res = $res->result();
        }

        if (count($res) == 0) {
            return null;
        } else
            return $res[0];

    }
}